
//
//  CourseNavView.m
//  ShowYork
//
//  Created by hxh on 2020/8/28.
//  Copyright © 2020 hxh. All rights reserved.
//

#import "LessonPageNavView.h"

@interface LessonPageNavView ()
@property (nonatomic,strong)UILabel *userlevel;
@property (nonatomic,strong)UIView *searchView;
@property (nonatomic,strong)UILabel *searchLb;
@property (nonatomic,strong)UIButton *centerBtn;
@property (nonatomic,strong)UIImageView *searchImgView;
//@property (nonatomic,strong)UIImageView *checkImgView;
//@property (nonatomic,strong)UIButton *checkBtn;
@property (nonatomic,strong)UIButton *searchBtn;
@property (nonatomic,strong)UIImageView *centerImgView;
@property (nonatomic,strong)UILabel *centerLb;
@property (nonatomic,strong)UIView *line;
@property (nonatomic,strong)UIImageView *backImgView;
@property (nonatomic,strong)UIButton *backBtn;
@end

@implementation LessonPageNavView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setUI];
    }
    return self;
}

- (void)setUI{
    
    self.userlevel = [[UILabel alloc]init];
    self.userlevel.text = @"高三";
    self.userlevel.textColor = [UIColor whiteColor];
    self.userlevel.font = font(14);
    [self addSubview:self.userlevel];
    
//    self.checkImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"course_check_down"]];
//    [self addSubview:self.checkImgView];
    
    self.searchView = [[UIView alloc]init];
    self.searchView.layer.cornerRadius = 15;
    self.searchView.backgroundColor = RGBA(243, 243, 243, 1);
    [self addSubview:self.searchView];
//
    self.centerBtn = [[UIButton alloc]init];
    [self.centerBtn addTarget:self action:@selector(goCenterMethod) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.centerBtn];
    
    
    self.centerLb = [[UILabel alloc]init];
    self.centerLb.text = @"学习";
    self.centerLb.textColor = [UIColor whiteColor];
    self.centerLb.font = font(10);
    [self addSubview:self.centerLb];
    
    self.centerImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"course_tag_study"]];
    self.centerImgView.highlightedImage = [UIImage imageNamed:@"course_tag_study_selected"];
    [self addSubview:self.centerImgView];
    
    
    self.searchLb = [[UILabel alloc]init];
    self.searchLb.text = @"";
    self.searchLb.textColor = RGBA(204, 204, 204, 1);
    self.searchLb.font = font(14);
    [self addSubview:self.searchLb];
    
    
    
    self.searchImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"course_search"]];
    [self addSubview:self.searchImgView];
    
//    self.checkBtn = [[UIButton alloc]init];
//    [self.checkBtn addTarget:self action:@selector(checkMethod) forControlEvents:UIControlEventTouchUpInside];
//    [self addSubview:self.checkBtn];
    
    self.searchBtn = [[UIButton alloc]init];
    [self.searchBtn addTarget:self action:@selector(searchMethod) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.searchBtn];
    
    self.backImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"common_back_normal_tag"]];
    self.backImgView.highlightedImage = [UIImage imageNamed:@"common_back_tag"];
    [self addSubview:self.backImgView];
    
    self.backBtn = [[UIButton alloc]init];
    [self.backBtn addTarget:self action:@selector(backMethod) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.backBtn];
    
    [self.backImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(16);
        make.bottom.mas_equalTo(self).offset(-12);
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];
    [self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.equalTo(self);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    
    [self.userlevel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.backImgView.mas_right).offset(12);
        make.centerY.mas_equalTo(self.backImgView);
    }];
    
    [self.searchView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(30);
        make.centerY.mas_equalTo(self.userlevel);
        make.right.equalTo(self.centerBtn.mas_left);
        make.left.equalTo(self.userlevel.mas_right).offset(10);
    }];
       
    [self.searchImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.searchView);
        make.left.equalTo(self.searchView).offset(8);
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];
    
    [self.searchLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.searchView);
        make.left.equalTo(self.searchImgView.mas_right).offset(3);
        make.right.equalTo(self.searchView).offset(-18);
    }];
    

//    [self.checkBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.top.bottom.mas_equalTo(self);
//        make.right.equalTo(self.checkImgView.mas_right);
//    }];


    [self.searchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.equalTo(self.searchView);
    }];

    [self.centerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self);
        make.right.equalTo(self);
        make.width.mas_equalTo(44);
    }];
    [self.centerImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.searchView);
        make.centerX.equalTo(self.centerBtn);
    }];
    [self.centerLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.centerImgView.mas_bottom);
        make.centerX.equalTo(self.centerImgView);
    }];

    self.line = [[UIButton alloc]init];
    self.line.backgroundColor = RGBA(226, 226, 226, 1);
    self.line.hidden = YES;
    [self addSubview:self.line];
    
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.left.right.equalTo(self);
        make.height.mas_equalTo(0.5);
    }];
    
    [self.userlevel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    
    
}

- (void)backMethod{
    if (self.delegate && [self.delegate respondsToSelector:@selector(popViewController)]) {
        [self.delegate popViewController];
    }
}

- (void)checkMethod{
    
//    self.checkBtn.selected =! self.checkBtn.selected;
//
//    if (self.delegate && [self.delegate respondsToSelector:@selector(showUserlevelWithStatus:)]) {
//        [self.delegate showUserlevelWithStatus:self.checkBtn.selected];
//    }
}
- (void)searchMethod{
    if (self.delegate && [self.delegate respondsToSelector:@selector(showSearchMore)]) {
        [self.delegate showSearchMore];
    }
}
- (void)goCenterMethod{
    if (self.delegate && [self.delegate respondsToSelector:@selector(showCourseCenter)]) {
        [self.delegate showCourseCenter];
    }
}

- (void)setNavTitle:(NSString *)navTitle{
    self.searchLb.text = navTitle;
}

- (void)updateAlpha:(CGFloat)alpha{
    if (alpha == 0) {
        self.userlevel.textColor = [UIColor whiteColor];
        self.centerLb.textColor = [UIColor whiteColor];
        self.centerImgView.highlighted = NO;
        self.backImgView.highlighted = NO;
        self.line.hidden = YES;
    }else{
        if (alpha >= 1) {
            self.line.hidden = NO;
        }
        self.userlevel.textColor = RGBA(0, 0, 0, alpha);
        self.centerLb.textColor = RGBA(0, 0, 0, alpha);
        self.centerImgView.highlighted = YES;
        self.backImgView.highlighted = YES;
    }
   
}

- (void)resetView{
    self.userlevel.textColor = RGBA(0, 0, 0, 1);
    self.centerLb.textColor = RGBA(0, 0, 0, 1);
    self.centerImgView.highlighted = YES;
    self.backImgView.highlighted = YES;
}

@end
